package org.wz.complex.work.controller.auth.sysinfo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.wz.complex.work.bean.Abc;
import org.wz.complex.work.bean.Pagi;
import org.wz.complex.work.bean.Res;
import org.wz.complex.work.controller.base.BaseController;
import org.wz.complex.work.entity.auth.sysinfo.SysinfoMenu;
import org.wz.complex.work.service.auth.sysinfo.SysinfoMenuService;

import java.util.List;


@RestController
@RequestMapping("/auth/sysinfo/menu")
public class SysinfoMenuController extends BaseController<SysinfoMenu, Object> {

    @Resource
    private SysinfoMenuService service;

    @GetMapping("/sidebar/{id}")
    public Res sidebar(@PathVariable(required = true, name = "id") String id) throws Exception {
        LambdaQueryWrapper<SysinfoMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysinfoMenu::getPid, 0L);
        wrapper.orderByAsc(SysinfoMenu::getSeq);
        wrapper.last(" limit 99 ");
        List<SysinfoMenu> list = service.list(wrapper);
        if (null != list && list.size() > 0) {
            list.forEach(menu -> {
                LambdaQueryWrapper<SysinfoMenu> subLqw = new LambdaQueryWrapper<>();
                subLqw.eq(SysinfoMenu::getPid, menu.getId());
                subLqw.orderByAsc(SysinfoMenu::getSeq);
                List<SysinfoMenu> subList = service.list(subLqw);
                menu.setSubList(subList);
            });
        }
        return Res.ok(list);
    }


    @GetMapping("/abc")
    public Res abc(Abc abc) throws Exception {
        return Res.ok(service.getAbc(abc));
    }



}



